// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'

import VueRouter from 'vue-router'
import routes from './router'
import '@/utils/filter'

Vue.use(VueRouter)

let router = new VueRouter({
  mode: 'history',
  routes:routes
})
//element-ui
import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element, { size: 'small', zIndex: 3000 });

Vue.config.productionTip = false


Vue.prototype.HistoryGoHome = false;//是否跳转到home页
router.beforeEach((to, from, next) => {
  if(from.path == "/"){
    Vue.prototype.HistoryGoHome = true;
  }else{
    Vue.prototype.HistoryGoHome = false;
  }
  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
